<html>
<head>
    <meta charset="UTF-8">
    <title>外部服务输入字段选择框</title>
    <link id="easyuiTheme"  href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
    <link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
    <link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
    <script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
    <script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
    <script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
    <script src="../../ffres/dict/all.js" type="text/javascript"></script>
    <a href="" target="_blank" id="commonLink" name="commonLink"></a>
    
</head>

<body class="easyui-layout">
    <div class="easyui-layout" title="" style="width:100%;height:100%;padding:0px;">
        <div data-options="region:'center',split:false" title="" style="width:25%;">
            <ul id="nav" class="easyui-tree" data-options="animate:true,
					lines:true,method:'get',
					animate:true" id="menu_app1">
        </div>
        <div data-options="region:'south',split:false" style="height:30px;text-align:center;padding:0px">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="doSelect()">选择返回</a>&nbsp;
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeForm()">&nbsp;关&nbsp;闭&nbsp;</a>
        </div>
    </div>

    <script>
        function createTree(rows, appModelId) {

            let key = 'recordKeyid',
                parentKey = 'appModelId',
                childKey = 'children';
            let r = [];
            let tmpMap = {};
            for (i = 0, l = rows.length; i < l; i++) {
                rows[i].id = rows[i][key];
                rows[i].text = `${rows[i].paramFieldName ? rows[i].paramFieldName +  "-" : ""}${rows[i].paramFieldCode}`;
                tmpMap[rows[i][key]] = rows[i];
			}
			
            for (i = 0, l = rows.length; i < l; i++) {
                if (tmpMap[rows[i][parentKey]] && rows[i][key] != rows[i][parentKey]) {
                    if (!tmpMap[rows[i][parentKey]][childKey])
                        tmpMap[rows[i][parentKey]][childKey] = [];
                    tmpMap[rows[i][parentKey]][childKey].push(rows[i]);
                } else {
                    r.push(rows[i]);
                }
            }
            return r;
        }

		var appId = $.getUrlParam('appId');
		var appModelId = $.getUrlParam('appModelId');

        var appModelInfo ;
		var selection = null;
        $(function() {

            $.restfulGet('../../api/app/model/info/' + appModelId ,null,function(data){
                appModelInfo = data.rows;
            });
            
            $('#nav').tree({

                queryParams: {
                    appModelId: appModelId,
                    ioType: "I",
					size: 20
                },
                loader: function(param, success, error) {
                    var url = `../../api/app/model/info/osrv/field`;
                    $.restfulPostJson(url, param, function(data) {
                        var rows = data.rows;
                        var root = createTree(rows);
                        
                        success(root);
                    }, error);
                },
                onClick: function(node) {
                    selection = node;
                },
                
            })
        });

        function doSelect() {
            if (selection) {
                window.parent.setPopOsrvInFieldChoice(selection);
                window.parent.JLEUtil.closewin();
            } else {
                $.messager.alert('提示', '请选择一条记录！');
            }
        }

        function closeForm() {
            window.parent.JLEUtil.closewin();
        }
    </script>
</body>

</html>